// **************************************************************
// COPYRIGHT(c)2022, Xidian University
// All rights reserved.
//
// IP LIB INDEX :  
// IP Name      :      
// File name    :  
// Module name  :  
// Full name    :  
// Time         : 2022
// Author       : Wang-Zhenuyu 
// Email        : 2047593704@qq.com
// Data         : 
// Version      : V 2.0 
// 
// Abstract     :
// Called by    :  
// 
// Modification history
// -----------------------------------------------------------------
// 
// 
//
// *****************************************************************

//*************************
//TIMESCALE
//*************************
`timescale 1ns/1ps

//*************************
//INFORMATION
//*************************

//*************************
//DEFINE(s)
//*************************

//*************************
//DEFINE MODULE PORT
//*************************
module pkt_analysis_m1(
    //数据输入
    input wire rst_n,
    input wire pkt_clk_i,
    input wire pkt_sop_i,
    input wire pkt_eop_i,
    input wire[255:0] pkt_data_i,
    input wire pbb_uca,
    input wire[23:0] pbb_i_sid,
    //数据输出
    output wire[8:0] layend,
    //output reg layend_en,
    output reg[0:1023] match_field,
    output wire analyser_is_working_o,
    output wire analyser_is_done_o
    //output reg[263:0] payload,
    //output reg payload_en
);

//*************************
//DEFINE LOCAL PARAMETER
//*************************
//parameter(s)
parameter IDLE = 3'b000;
parameter L2   = 3'b001;
parameter L2_5 = 3'b011;
parameter L3   = 3'b010;
parameter L4   = 3'b100;

parameter field_tab_item_00_i=8'h04;//MAC目的地址前16bit                     
parameter field_tab_item_01_i=8'h00;//MAC目的地址中16bit                     
parameter field_tab_item_02_i=8'h0c;//MAC目的地址后16bit                     
parameter field_tab_item_03_i=8'h08;//MAC源地址前16bit                     
parameter field_tab_item_04_i=8'h14;//MAC源地址中16bit                     
parameter field_tab_item_05_i=8'h10;//MAC源地址后16bit                     
parameter field_tab_item_06_i=8'h1c;//VLAN标签
parameter field_tab_item_07_i=8'h18;//服务类别和VLAN id      
parameter field_tab_item_08_i=8'h24;//QINQ vlan 标签   
parameter field_tab_item_09_i=8'h20;//QINQ vlan id 和cos字段
parameter field_tab_item_10_i=8'h03;//以太网帧类型 
parameter field_tab_item_11_i=8'h05;//服务类型
parameter field_tab_item_12_i=8'h1d;//IPv4源地址高16bit或IPv6源地址[95:80]                    
parameter field_tab_item_13_i=8'h19;//IPv4源地址低16bit或IPV6源地址[79:64]
parameter field_tab_item_14_i=8'h25;//IPv4目的地址高16bit或IPv6源地址[63:48]
parameter field_tab_item_15_i=8'h21;//IPv4目的地址低16bit或IPv6源地址[47:32]
parameter field_tab_item_16_i=8'h15;//IPv6源地址[127:112]
parameter field_tab_item_17_i=8'h11;//IPv6源地址[111:96]
parameter field_tab_item_18_i=8'h2d;//IPv6源地址[31:16]
parameter field_tab_item_19_i=8'h29; //IPv6源地址[15:0]
parameter field_tab_item_20_i=8'h35; //IPv6目的地址[127:112]
parameter field_tab_item_21_i=8'h31;//IPv6目的地址[111:96]
parameter field_tab_item_22_i=8'h3d;//IPv6目的地址[95:80]
parameter field_tab_item_23_i=8'h39;//IPv6目的地址[79:64]
parameter field_tab_item_24_i=8'h45;//IPv6目的地址[63:48]
parameter field_tab_item_25_i=8'h41;//IPv6目的地址[47:32]
parameter field_tab_item_26_i=8'h4d;//IPv6目的地址[31:16]
parameter field_tab_item_27_i=8'h49; //IPv6目的地址[15:0]
parameter field_tab_item_28_i=8'h15;//IPv4上层协议
parameter field_tab_item_29_i=8'h07;//IPv6上层协议
parameter field_tab_item_30_i=8'h06;//TCP/UDP/SCTP源端口号
parameter field_tab_item_31_i=8'h02;//TCP/UDP/SCTP目的端口号
parameter field_tab_item_32_i=8'h05; //业务类别
parameter field_tab_item_33_i=8'h1e;//TCPflag,低12bit有效
//*************************
//INNER SIGNAL DECLARATION
//*************************
//REGS
reg[2:0] current_layer,next_layer;
reg pkt_eop_d1,pkt_eop_d2,pkt_eop_d3,pkt_eop_d4,pkt_eop_d5;
reg pkt_sop_d1;
reg[3:0] l2_end;
reg[4:0] l3_end;
reg[1:0] flag;
reg[3:0] l4_flag;
reg[255:0] pkt_data_d1,pkt_data_d2,pkt_data_d3,pkt_data_d4,pkt_data_d5,pkt_data_d6,pkt_data_d7;
reg is_vlan;
reg is_qinq;
reg is_ethtype;
reg is_mpls;
reg[3:0] mpls_num;
reg[159:0] mpls_data;
reg [1:0]l2_word_cnt;
reg [1:0]l3_dword_cnt;
reg [1:0]l4_dword_cnt;
reg pkt_analyser_is_working_d1,pkt_analyser_is_working_d2;
reg[3:0] ipv4_head_length;
//WIRES
wire[15:0] window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,window_reg_04_wdata_o,window_reg_05_wdata_o;
wire[15:0] window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,window_reg_09_wdata_o,window_reg_10_wdata_o;
wire[2:0]  window_reg_11_wdata_o;
wire[15:0] window_reg_12_wdata_o,window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_16_wdata_o;
wire[15:0] window_reg_17_wdata_o,window_reg_18_wdata_o,window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o;
wire[15:0] window_reg_22_wdata_o,window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,window_reg_27_wdata_o;
wire[7:0]  window_reg_28_wdata_o,window_reg_29_wdata_o,window_reg_32_wdata_o;
wire[15:0] window_reg_30_wdata_o,window_reg_31_wdata_o,window_reg_33_wdata_o;

//***********************
//MAIN CODE
//***********************
wire[255:0] pkt_data_for_l2;
wire[255:0] pkt_data_for_l2_5;
wire[255:0] pkt_data_for_l3;
wire[255:0] pkt_data_for_l4;

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_data_d1 <= 0;
        pkt_data_d2 <= 0;
    end
    else
    begin
        pkt_data_d1 <= pkt_data_i;
        pkt_data_d2 <= pkt_data_d1;
    end
end

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_data_d3 <= 0;
    end
    else
    begin
        pkt_data_d3 <= pkt_data_for_l2_5;
    end
end

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_data_d4 <= 0;
        pkt_data_d5 <= 0;
    end
    else
    begin
        pkt_data_d4 <= pkt_data_for_l3;
        pkt_data_d5 <= pkt_data_d4;
    end
end

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_data_d6 <= 0;
        pkt_data_d7 <= 0;
    end
    else
    begin
        pkt_data_d6 <= pkt_data_for_l4;
        pkt_data_d7 <= pkt_data_d6;
    end
end

//***********************************************************
//flag  00/ethernet/112bits  01/vlan/144bits  10/qinq/176bits
//***********************************************************
assign pkt_data_for_l2 = pkt_data_d1[255:0];
//*************************
//mpls层
//*************************
assign pkt_data_for_l2_5 = (flag==2'b00)?{pkt_data_d2[143:0],pkt_data_d1[255:144]}:
                           (flag==2'b01)?{pkt_data_d2[111:0],pkt_data_d1[255:112]}:
                           (flag==2'b10)?{pkt_data_d2[79:0],pkt_data_d1[255:80]}:256'b0;
//*************************
//网络层
//*************************

assign pkt_data_for_l3 =   (!is_mpls)?pkt_data_d3:
                           (mpls_num==3'd1)?{pkt_data_d3[223:0],pkt_data_for_l2_5[255:224]}:
                           (mpls_num==3'd2)?{pkt_data_d3[191:0],pkt_data_for_l2_5[255:192]}:
                           (mpls_num==3'd3)?{pkt_data_d3[159:0],pkt_data_for_l2_5[255:160]}:
                           (mpls_num==3'd4)?{pkt_data_d3[127:0],pkt_data_for_l2_5[255:128]}:
                           (mpls_num==3'd5)?{pkt_data_d3[95:0],pkt_data_for_l2_5[255:96]}:256'b0;
//***************************************************************
//20B/0101   24B/0110   28B/0111  32B/1000  36B/1001  40B/1010  44B/1011  48B/1100  52B/1101  56B/1110  60B/1111 ipv4֡ͷ����Ϊ20B-60B
//***************************************************************
assign pkt_data_for_l4 = (/*ipv4_head_length*/l4_flag==4'b0101)?{pkt_data_d5[95:0],pkt_data_d4[255:96]}:
                        (/*ipv4_head_length*/l4_flag==4'b0110)?{pkt_data_d5[63:0],pkt_data_d4[255:64]}:
                        (/*ipv4_head_length*/l4_flag==4'b0111)?{pkt_data_d5[31:0],pkt_data_d4[255:32]}:
                        (/*ipv4_head_length*/l4_flag==4'b1000)?{pkt_data_d4[255:0]}:
                        (/*ipv4_head_length*/l4_flag==4'b1001)?{pkt_data_d4[223:0],pkt_data_for_l3[255:224]}:
                        (/*ipv4_head_length*/l4_flag==4'b1010)?{pkt_data_d4[191:0],pkt_data_for_l3[255:192]}:
                        (/*ipv4_head_length*/l4_flag==4'b1011)?{pkt_data_d4[159:0],pkt_data_for_l3[255:160]}:
                        (/*ipv4_head_length*/l4_flag==4'b1100)?{pkt_data_d4[127:0],pkt_data_for_l3[255:128]}:
                        (/*ipv4_head_length*/l4_flag==4'b1101)?{pkt_data_d4[95 :0],pkt_data_for_l3[255:96]}:
                        (/*ipv4_head_length*/l4_flag==4'b1110)?{pkt_data_d4[63 :0],pkt_data_for_l3[255:64]}: 
                        (/*ipv4_head_length*/l4_flag==4'b1111)?{pkt_data_d4[31 :0],pkt_data_for_l3[255:32]}:
                         256'b0;
//***************************************************************
//20B/0101   24B/0110   28B/0111  32B/1000  36B/1001  40B/1010  44B/1011  48B/1100  52B/1101  56B/1110  60B/1111 ipv4֡ͷ����Ϊ20B-60B
//***************************************************************
wire [263:0]pkt_data_for_payload;
reg [3:0]tcp_flag;
                         
assign pkt_data_for_payload = (/*udp_head_length*/tcp_flag==4'b0010)?{pkt_data_d7[191:0],pkt_data_d6[255:184]}:
                              (/*tcp_head_length*/tcp_flag==4'b0101)?{pkt_data_d7[95:0],pkt_data_d6[255:88]}:
                              (/*tcp_head_length*/tcp_flag==4'b0110)?{pkt_data_d7[63:0],pkt_data_d6[255:56]}:
                              (/*tcp_head_length*/tcp_flag==4'b0111)?{pkt_data_d7[31:0],pkt_data_d6[255:24]}:
                              (/*tcp_head_length*/tcp_flag==4'b1000)?{pkt_data_d6[255:0],pkt_data_for_l4[255:248]}:
                              (/*tcp_head_length*/tcp_flag==4'b1001)?{pkt_data_d6[223:0],pkt_data_for_l4[255:216]}:
                              (/*tcp_head_length*/tcp_flag==4'b1010)?{pkt_data_d6[191:0],pkt_data_for_l4[255:184]}:
                              (/*tcp_head_length*/tcp_flag==4'b1011)?{pkt_data_d6[159:0],pkt_data_for_l4[255:152]}:
                              (/*tcp_head_length*/tcp_flag==4'b1100)?{pkt_data_d6[127:0],pkt_data_for_l4[255:120]}:
                              (/*tcp_head_length*/tcp_flag==4'b1101)?{pkt_data_d6[95:0],pkt_data_for_l4[255:88]}:
                              (/*tcp_head_length*/tcp_flag==4'b1110)?{pkt_data_d6[63:0],pkt_data_for_l4[255:56]}:
                              (/*tcp_head_length*/tcp_flag==4'b1111)?{pkt_data_d6[31:0],pkt_data_for_l4[255:24]}:264'b0;
wire [255:0]pkt_data_in_layer;
assign pkt_data_in_layer = (current_layer==3'b100) ? pkt_data_for_l4 :
                           (current_layer==3'b010) ? pkt_data_for_l3 :
                           (current_layer==3'b011) ? pkt_data_for_l2_5 :
                           (current_layer==3'b001) ? pkt_data_for_l2 : 256'b0;

//l2_end和l3_end
always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        l2_end <= 4'b0;
    end
    else if((l2_word_cnt==2'b00) && (pkt_data_for_l2[159:144]!=16'h8100) && (current_layer==L2))
    begin
        l2_end <= 4'd7;
    end
    else if((l2_word_cnt==2'b00) && (pkt_data_for_l2[159:144]==16'h8100) && (pkt_data_for_l2[127:112]!=16'h8100) && (current_layer==L2))
    begin
        l2_end <= 4'd9;
    end
    else if((l2_word_cnt==2'b00) && (pkt_data_for_l2[159:144]==16'h8100) && (pkt_data_for_l2[127:112]==16'h8100) && (current_layer==L2))
    begin
        l2_end <= 4'd11;
    end
    else
    begin
        l2_end <= l2_end;
    end
end
always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        l3_end <= 5'b0;
    end
    else if(current_layer==L2)
    begin
        l3_end <= 5'b0;
    end
    else if((current_layer==L3) && pkt_data_for_l3[255:252]==4'd4 && (l3_dword_cnt==2'b0))
    begin
        l3_end <= ipv4_head_length << 1;
    end
    else if((current_layer==L4) && pkt_data_for_l3[255:252]==4'd6 && (l3_dword_cnt==2'b0))
    begin
        l3_end <= 5'd10;
    end
end

assign layend = {l2_end,l3_end};
/*
always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        layend_en <= 1'b0;
    end
    else(layend != 9'b0)
  */  

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        current_layer <= IDLE;
    end
    else
    begin
        current_layer <= next_layer;
    end
end


reg is_ipv6;
reg[7:0] ipv6_next_header;
reg[7:0] ipv6_next_header_len;
reg ether_type_en;
reg[15:0] ether_type;
reg[7:0] ipv6_protocol;
reg ipv6_protocol_en;
reg ethtype_is_ipv4;
reg is_l4;
reg is_tcp;
reg is_udp;
reg is_sctp;

always@(*)
begin
    case(current_layer)
      IDLE:
        begin
            if(pkt_sop_i)
            begin
                next_layer = L2;
            end
            else
            begin
                next_layer = IDLE;
            end
        end
      L2:
        begin
            if(pkt_eop_d5 || l2_word_cnt>2'd3)
            begin
                next_layer = IDLE;
            end
            else if(((l2_word_cnt==2'b0) && (pkt_data_for_l2[159:144]==16'h0800 || pkt_data_for_l2[159:144]==16'h0806 || pkt_data_for_l2[159:144]==16'h86DD))||//以太网帧
                    ((l2_word_cnt==2'b0) && (pkt_data_for_l2[127:112]==16'h0800 || pkt_data_for_l2[127:112]==16'h0806 || pkt_data_for_l2[127:112]==16'h86DD))||//VLAN帧类型
                    ((l2_word_cnt==2'b0) && (pkt_data_for_l2[95:80]==16'h0800 || pkt_data_for_l2[95:80]==16'h0806 || pkt_data_for_l2[95:80]==16'h86DD)))//QINQ帧
                next_layer = L2_5;
            else if(((l2_word_cnt==2'b0) && (pkt_data_for_l2[159:144]==16'h8847 || pkt_data_for_l2[159:144]==16'h8848 ))||//以太网帧
                    ((l2_word_cnt==2'b0) && (pkt_data_for_l2[127:112]==16'h8847 || pkt_data_for_l2[127:112]==16'h8848 ))||//VLAN帧类型
                    ((l2_word_cnt==2'b0) && (pkt_data_for_l2[95:80]==16'h8847 || pkt_data_for_l2[95:80]==16'h8848 )))//QINQ帧类型
                next_layer = L2_5;
            else
            begin
                next_layer = L2;
            end
        end
      L2_5:
        begin
            next_layer = L3;
        end
      L3:
        begin
            if(pkt_eop_d5 || (is_ipv6 && (ipv6_next_header!=8'd6) && (ipv6_next_header!=8'd17) && (ipv6_next_header!=8'd132) && (l3_dword_cnt[1:0]==2'b01)))
            begin
                next_layer = IDLE;
            end
            else if(l3_dword_cnt[1:0]==2'b01 && ipv4_head_length!=4'd0)
            begin
                next_layer = L4;
            end
            else if(l3_dword_cnt[1:0]==2'b01 && ipv6_next_header_len==8'd1 &&
                    ipv6_next_header!=8'd0 && ipv6_next_header!=8'd43 &&
                    ipv6_next_header!=8'd60 && ipv6_next_header!=8'd44 &&
                    ipv6_next_header!=8'd51 )//需要修改
            begin
                next_layer = L4;
            end
            else
            begin
                next_layer = L3;
            end
        end
      L4:
        begin
            if(pkt_eop_d5 || l4_dword_cnt>=2'd3)
            begin
                next_layer = IDLE;
            end
            else
            begin
                next_layer = L4;
            end
        end
      default:
        begin
            next_layer = IDLE;
        end
    endcase
end
    
always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_eop_d1 <= 0;
        pkt_eop_d2 <= 0;
        pkt_eop_d3 <= 0;
        pkt_eop_d4 <= 0;
        pkt_eop_d5 <= 0;
    end
    else
    begin
        pkt_eop_d1 <= pkt_eop_i;
        pkt_eop_d2 <= pkt_eop_d1;
        pkt_eop_d3 <= pkt_eop_d2;
        pkt_eop_d4 <= pkt_eop_d3;
        pkt_eop_d5 <= pkt_eop_d4;
    end
end

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_sop_d1 <= 1'b0;
    end
    else
    begin
        pkt_sop_d1 <= pkt_sop_i;
    end
end

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        l2_word_cnt          <= 2'd0;
        l3_dword_cnt         <= 2'd0;
        l4_dword_cnt         <= 2'd0;
        flag                 <= 2'b0;
        is_mpls              <= 1'd0;
        is_ipv6              <= 1'd0;
        is_ethtype           <= 1'd0;
        is_vlan              <= 1'd0;
        is_qinq              <= 1'd0;
        mpls_data            <= 160'd0;
        mpls_num             <= 3'd0;
        ethtype_is_ipv4      <= 1'b0;
        ether_type           <= 16'd0;
        ether_type_en        <= 1'b0;
        ipv4_head_length     <= 4'd0;
        ipv6_next_header     <= 8'd59;
        ipv6_next_header_len <= 8'd5;
        ipv6_protocol        <= 8'd0;
        ipv6_protocol_en     <= 1'b0;
        is_l4                <= 1'b0;
        l4_flag              <= 4'd0;
        is_tcp               <= 1'b0;
        is_udp               <= 1'b0;
        is_sctp              <= 1'b0;
        //payload              <= 264'b0;
        //payload_en           <= 1'b0;
    end
    else 
    begin
        case(current_layer)
          IDLE:
          begin
            l2_word_cnt          <= 2'd0;
            l3_dword_cnt         <= 2'd0;
            l4_dword_cnt         <= 2'd0;
            flag                 <= 2'b0;
            is_mpls              <= 1'd0;
            is_ipv6              <= 1'd0;
            is_ethtype           <= 1'd0;
            is_vlan              <= 1'd0;
            is_qinq              <= 1'd0;
            mpls_data            <= 160'd0;
            mpls_num             <= 3'd0;
            ethtype_is_ipv4      <= 1'b0;
            ether_type           <= 16'd0;
            ether_type_en        <= 1'b0;
            ipv4_head_length     <= 4'd0;
            ipv6_next_header     <= 8'd59;
            ipv6_next_header_len <= 8'd5;
            ipv6_protocol        <= 8'd0;
            ipv6_protocol_en     <= 1'b0;
            is_l4                <= 1'b0;
            l4_flag              <= 4'd0;
            is_tcp               <= 1'b0;
            is_udp               <= 1'b0;
            is_sctp              <= 1'b0;
            //payload              <= 264'b0;
            //payload_en           <= 1'b0;
          end
          L2:
          begin
            if(l2_word_cnt==2'd0 && pkt_data_for_l2[159:144]==16'h8100 && pkt_data_for_l2[127:112]==16'h8100)//QINQ
            begin
                is_ethtype <= 1'b0;
                is_vlan    <= 1'b0;
                is_qinq    <= 1'b1;
            end
            else if(l2_word_cnt==2'b0 && pkt_data_for_l2[159:144]==16'h8100)
            begin
                is_ethtype <= 1'b0;
                is_vlan    <= 1'b1;
                is_qinq    <= 1'b0;
            end
            else if(l2_word_cnt==2'd0 && pkt_data_for_l2[159:144]!=16'h8100)
            begin
                is_ethtype <= 1'b1;
                is_vlan    <= 1'b0;
                is_qinq    <= 1'b0;
            end
            else
            begin
                is_ethtype <= is_ethtype;
                is_vlan    <= is_vlan;
                is_qinq    <= is_qinq;
            end
            if(l2_word_cnt==2'd0 && pkt_data_for_l2[159:144]!=16'h8100)
            begin
                l2_word_cnt   <= l2_word_cnt;
                flag          <= 2'b00;//普通以太网帧
                ether_type    <= pkt_data_for_l2[159:144];
                ether_type_en <= 1'b1;
                if(pkt_data_for_l2[159:144]==16'h0800)
                begin
                    is_mpls         <= 1'b0;
                    ethtype_is_ipv4 <= 1'b1;
                    is_ipv6         <= 1'b0;
                end
                else if(pkt_data_for_l2[159:144]==16'h86DD)
                begin
                    is_mpls         <= 1'b0;
                    ethtype_is_ipv4 <= 1'b0;
                    is_ipv6         <= 1'b1;
                end
                else if(pkt_data_for_l2[159:144]==16'h8847 || pkt_data_for_l2[159:144]==16'h8848)
                begin
                    is_mpls         <= 1'b1;
                    ethtype_is_ipv4 <= 1'b0;
                    is_ipv6         <= 1'b0;
                end
                else 
                begin
                    is_mpls         <= is_mpls;
                    ethtype_is_ipv4 <= ethtype_is_ipv4;
                    is_ipv6         <= is_ipv6;
                end
            end
            else if(l2_word_cnt==2'd0 && pkt_data_for_l2[159:144]==16'h8100 && pkt_data_for_l2[127:112]!=16'h8100)
            begin
                l2_word_cnt   <= l2_word_cnt;
                flag          <= 2'b01;//VLAN帧
                ether_type    <= pkt_data_for_l2[127:112];
                ether_type_en <= 1'b1;
                if(pkt_data_for_l2[127:112]==16'h0800)
                begin
                    is_mpls         <= 1'b0;
                    ethtype_is_ipv4 <= 1'b1;
                    is_ipv6         <= 1'b0;
                end
                else if(pkt_data_for_l2[127:112]==16'h86DD)
                begin
                    is_mpls         <= 1'b0;
                    ethtype_is_ipv4 <= 1'b0;
                    is_ipv6         <= 1'b1;
                end
                else if(pkt_data_for_l2[127:112]==16'h8847 || pkt_data_for_l2[127:112]==16'h8848)
                begin
                    is_mpls         <= 1'b1;
                    ethtype_is_ipv4 <= 1'b0;
                    is_ipv6         <= 1'b0;
                end
                else
                begin
                    is_mpls         <= is_mpls;
                    ethtype_is_ipv4 <= ethtype_is_ipv4;
                    is_ipv6         <= is_ipv6;
                end
            end
            else if((l2_word_cnt==2'b00) && (pkt_data_for_l2[159:144]==16'h8100) && (pkt_data_for_l2[127:112]==16'h8100))//qinq֡
            begin
                l2_word_cnt     <= l2_word_cnt;
                flag            <= 2'b10;       //QINQ帧
                ether_type      <= pkt_data_for_l2[95:80];
                ether_type_en   <= 1'b1;
                if(pkt_data_for_l2[95:80]==16'h0800)
                begin 
                    ethtype_is_ipv4 <= 1'b1;
                    is_ipv6         <= 1'b0;
                    is_mpls         <= 1'b0;
                end
                else if(pkt_data_for_l2[95:80]==16'h86DD)
                begin
                    ethtype_is_ipv4 <= 1'b0;
                    is_ipv6         <= 1'b1;
                    is_mpls         <= 1'b0;
                end
                else if(pkt_data_for_l2[95:80]==16'h8847 || pkt_data_for_l2[95:80]==16'h8848)
                begin
                    ethtype_is_ipv4 <= 1'b0;
                    is_ipv6         <= 1'b0;
                    is_mpls         <= 1'b1;
                end
                else
                begin
                    ethtype_is_ipv4 <= ethtype_is_ipv4;
                    is_ipv6         <= is_ipv6;
                    is_mpls         <= is_mpls;
                end
            end
            else
            begin
                l2_word_cnt    <= l2_word_cnt +2'd1;
                ether_type     <= ether_type;
                flag           <= flag;
                ether_type_en  <= ether_type_en;
                ethtype_is_ipv4  <= ethtype_is_ipv4;
                is_ipv6        <= is_ipv6;
                is_mpls        <= is_mpls;
            end
          end
          L2_5:
          begin
            if(!is_mpls)
            begin   
                mpls_num  <= 3'd0;
                mpls_data <= 160'd0;
            end
            else if(pkt_data_for_l2_5[232]==1'b1)
            begin
                mpls_num  <= 3'd1;
                mpls_data <= {pkt_data_for_l2_5[255:224],128'b0};
            end
            else if(pkt_data_for_l2_5[200]==1'b1)
            begin
                mpls_num  <= 3'd2;
                mpls_data <= {pkt_data_for_l2_5[255:192],96'b0};
            end
            else if(pkt_data_for_l2_5[168]==1'b1)
            begin
                mpls_num  <= 3'd3;
                mpls_data <= {pkt_data_for_l2_5[255:160],64'b0};
            end
            else if(pkt_data_for_l2_5[136]==1'b1)
            begin
                mpls_num  <= 3'd4;
                mpls_data <= {pkt_data_for_l2_5[255:128],32'b0};
            end
            else if(pkt_data_for_l2_5[104]==1'b1)
            begin
                mpls_num  <= 3'd5;
                mpls_data <= {pkt_data_for_l2_5[255:96]};
            end
            else
            begin
                mpls_num  <= 3'd0;
                mpls_data <= 160'b0;
            end
          end
          //ipv4以32bit为单位
          //ipv6以64bit为单位
          L3:
          begin
                if((pkt_data_for_l3[255:252]==4'd4) && (ethtype_is_ipv4 || is_mpls) && (l3_dword_cnt==2'd0))
                begin
                    ipv4_head_length <= pkt_data_for_l3[251:248];
                    ipv6_next_header     <= ipv6_next_header;
                    ipv6_next_header_len <= ipv6_next_header_len;
                    if(ethtype_is_ipv4!=1'b1)
                        ethtype_is_ipv4 <= 1'b1;
                    else
                        ethtype_is_ipv4 <= ethtype_is_ipv4;
                end
                else if((pkt_data_for_l3[255:252]==4'd6) && (is_ipv6 || is_mpls) && (l3_dword_cnt==2'd0))
                begin
                    ipv4_head_length     <= ipv4_head_length;
                    if(pkt_data_for_l3[207:200]==8'd6 || pkt_data_for_l3[207:200]==8'd17 || pkt_data_for_l3[207:200]==8'd132)
                    begin
                        ipv6_next_header     <= pkt_data_for_l3[207:200];
                        ipv6_next_header_len <= ipv6_next_header_len-8'd4;
                    end
                    else
                    begin
                        ipv6_next_header     <= ipv6_next_header;
                        ipv6_next_header_len <= ipv6_next_header_len;
                    end
                    if(is_ipv6!=1'b1)
                        is_ipv6 <= 1'b1;
                    else
                        is_ipv6<= is_ipv6;
                 end
                else
                begin
                    ipv4_head_length     <= ipv4_head_length;
                    ipv6_next_header_len <= ipv6_next_header_len;
                    ipv6_next_header     <= ipv6_next_header    ;
                end

                if((pkt_data_for_l3[183:176]==8'd6 && pkt_data_for_l3[255:252]==4'd4) || (pkt_data_for_l3[207:200]==8'd6 && pkt_data_for_l3[255:252]==4'd6))
                begin
                    is_tcp  <= 1'b1;
                    is_udp  <= 1'b0;
                    is_sctp <= 1'b0;
                end
                else if((pkt_data_for_l3[183:176]==8'd17 && pkt_data_for_l3[255:252]==4'd4) || (pkt_data_for_l3[207:200]==8'd17 && pkt_data_for_l3[255:252]==4'd6))
                begin
                    is_tcp  <= 1'b0;
                    is_udp  <= 1'b1;
                    is_sctp <= 1'b0;
                end
                else if((pkt_data_for_l3[183:176]==8'd132 && pkt_data_for_l3[255:252]==4'd4) || (pkt_data_for_l3[207:200]==8'd132 && pkt_data_for_l3[255:252]==4'd6))
                begin
                    is_tcp  <= 1'b0;
                    is_udp  <= 1'b0;
                    is_sctp <= 1'b1;
                end
                else
                begin
                    is_tcp  <= is_tcp;
                    is_udp  <= is_udp;
                    is_sctp <= is_sctp;
                end

                if(ipv4_head_length!=0)
                begin
                    l4_flag <= ipv4_head_length;
                    is_l4   <= 1'b1;
                end
                else if(is_ipv6 && (l3_dword_cnt==2'd1) && (ipv6_next_header_len==8'd1) &&
                    (ipv6_next_header!=8'd0) &&
                    (ipv6_next_header!=8'd59) &&
                    (ipv6_next_header!=8'd50) &&
                    (ipv6_next_header!=8'd51) &&
                    (ipv6_next_header!=8'd43) &&
                    (ipv6_next_header!=8'd60) &&
                    (ipv6_next_header!=8'd44))
                begin   
                    is_l4            <= 1'b1;
                    ipv6_protocol_en <= 1'b1;
                    ipv6_protocol    <= ipv6_next_header;
                    l4_flag          <= 4'b1010;      //ipv6帧头40字节
                end
                else
                begin
                    l3_dword_cnt <= l3_dword_cnt + 2'd1;
                    is_l4            <= is_l4;
                    l4_flag          <= l4_flag;
                    ipv6_protocol_en <= ipv6_protocol_en;
                    ipv6_protocol    <= ipv6_protocol;
                end
            end
          L4:
          begin
            if(l4_dword_cnt==2'b00)
            begin
                if(is_udp)
                    tcp_flag <= 4'b0010;
                else if(is_sctp)
                    tcp_flag <= 4'b0100;
                else if(is_tcp)
                    tcp_flag <= pkt_data_for_l4[159:156];
                else
                    tcp_flag <= 4'b0000;
                end
             /*
                if(l4_dword_cnt==2'b10)
                begin
                     //l4_dword_cnt <= l4_dword_cnt;
                     payload    <= pkt_data_for_payload;
                     payload_en <= 1'b1;
                 end
                else
                begin
                     payload    <= payload;
                     payload_en <= payload_en;
                     // l4_dword_cnt <= l4_dword_cnt +2'd1;
                 end
                 */
                 l4_dword_cnt <= l4_dword_cnt +2'd1;
          end
          default:
           begin
            l2_word_cnt          <= 2'd0;
            l3_dword_cnt         <= 2'd0;
            l4_dword_cnt         <= 2'd0;
            flag                 <= 2'b0;
            is_mpls              <= 1'd0;
            is_ipv6              <= 1'd0;
            is_ethtype           <= 1'd0;
            is_vlan              <= 1'd0;
            is_qinq              <= 1'd0;
            mpls_data            <= 160'd0;
            mpls_num             <= 3'd0;
            ethtype_is_ipv4      <= 1'b0;
            ether_type           <= 16'd0;
            ether_type_en        <= 1'b0;
            ipv4_head_length     <= 4'd0;
            ipv6_next_header     <= 8'd59;
            ipv6_next_header_len <= 8'd5;
            ipv6_protocol        <= 8'd0;
            ipv6_protocol_en     <= 1'b0;
            is_l4                <= 1'b0;
            l4_flag              <= 4'd0;
            is_tcp               <= 1'b0;
            is_udp               <= 1'b0;
            is_sctp              <= 1'b0;
            //payload              <= 264'b0;
            //payload_en           <= 1'b0;
          end
        endcase
    end
end
wire pkt_analyser_is_working;
assign pkt_analyser_is_working = ((current_layer==3'b001) || (current_layer==3'b010) || (current_layer==3'b100) || (current_layer==3'b011)) ? 1'b1 : 1'b0;
assign analyser_is_working_o   = pkt_analyser_is_working; 

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        pkt_analyser_is_working_d1 <= 1'd0;
        pkt_analyser_is_working_d2 <= 1'd0;
    end
    else
    begin
        pkt_analyser_is_working_d1 <= pkt_analyser_is_working;
        pkt_analyser_is_working_d2 <= pkt_analyser_is_working_d1;
    end
end

assign analyser_is_done_o = (!pkt_analyser_is_working_d1) & (pkt_analyser_is_working_d2);

always@(posedge pkt_clk_i or negedge rst_n)
begin
    if(!rst_n)
    begin
        match_field <= 1024'b0;
    end
    else if(ethtype_is_ipv4 && !is_vlan && !is_qinq)
    begin
        if(window_reg_28_wdata_o==8'd6)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            window_reg_30_wdata_o,window_reg_31_wdata_o,window_reg_33_wdata_o,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_28_wdata_o==8'd17)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_28_wdata_o==8'd132)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else 
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
    end

    else if(ethtype_is_ipv4 && is_vlan && !is_qinq)
    begin
        if(window_reg_28_wdata_o==8'd6)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            window_reg_30_wdata_o,window_reg_31_wdata_o,window_reg_33_wdata_o,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_28_wdata_o==8'd17)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_28_wdata_o==8'd132)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else 
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
    end

    else if(ethtype_is_ipv4 && !is_vlan && is_qinq)
    begin
        if(window_reg_28_wdata_o==8'd6)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            window_reg_30_wdata_o,window_reg_31_wdata_o,window_reg_33_wdata_o,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_28_wdata_o==8'd17)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_28_wdata_o==8'd132)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else 
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,window_reg_12_wdata_o,window_reg_13_wdata_o,
                            window_reg_14_wdata_o,window_reg_15_wdata_o,128'b0,128'b0,window_reg_28_wdata_o,8'b0,
                            16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
    end

    else if(is_ipv6 && !is_vlan && !is_qinq)
    begin
        if(window_reg_29_wdata_o==8'd6)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,
                            window_reg_12_wdata_o,window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,window_reg_30_wdata_o,window_reg_31_wdata_o,
                            window_reg_33_wdata_o,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_29_wdata_o==8'd17)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,window_reg_30_wdata_o,
                            window_reg_31_wdata_o,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_29_wdata_o==8'd132)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,16'b0,16'b0,window_reg_30_wdata_o,
                            window_reg_31_wdata_o,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else 
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,16'b0,16'b0,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
    end
    else if(is_ipv6 && is_vlan && !is_qinq)
    begin
        if(window_reg_29_wdata_o==8'd6)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,window_reg_30_wdata_o,window_reg_31_wdata_o,
                            window_reg_33_wdata_o,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_29_wdata_o==8'd17)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,
                            16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_29_wdata_o==8'd132)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,
                            8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else 
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,16'b0,16'b0,window_reg_10_wdata_o,
                            window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,window_reg_12_wdata_o,
                            window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,window_reg_18_wdata_o,
                            window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
    end
    else if(is_ipv6 && !is_vlan && is_qinq)
    begin
        if(window_reg_29_wdata_o==8'd6)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,
                            window_reg_12_wdata_o,window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,
                            window_reg_18_wdata_o,window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,window_reg_30_wdata_o,window_reg_31_wdata_o,
                            window_reg_33_wdata_o,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_29_wdata_o==8'd17)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,
                            window_reg_12_wdata_o,window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,
                            window_reg_18_wdata_o,window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,window_reg_30_wdata_o,window_reg_31_wdata_o,
                            16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else if(window_reg_29_wdata_o==8'd132)
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,
                            window_reg_12_wdata_o,window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,
                            window_reg_18_wdata_o,window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,16'b0,16'b0,window_reg_30_wdata_o,
                            window_reg_31_wdata_o,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
        else 
        begin
            match_field <= {window_reg_00_wdata_o,window_reg_01_wdata_o,window_reg_02_wdata_o,window_reg_03_wdata_o,
                            window_reg_04_wdata_o,window_reg_05_wdata_o,window_reg_06_wdata_o,window_reg_07_wdata_o,window_reg_08_wdata_o,
                            window_reg_09_wdata_o,window_reg_10_wdata_o,window_reg_11_wdata_o,5'b0,32'b0,32'b0,window_reg_16_wdata_o,window_reg_17_wdata_o,
                            window_reg_12_wdata_o,window_reg_13_wdata_o,window_reg_14_wdata_o,window_reg_15_wdata_o,
                            window_reg_18_wdata_o,window_reg_19_wdata_o,window_reg_20_wdata_o,window_reg_21_wdata_o,window_reg_22_wdata_o,
                            window_reg_23_wdata_o,window_reg_24_wdata_o,window_reg_25_wdata_o,window_reg_26_wdata_o,
                            window_reg_27_wdata_o,8'b0,window_reg_29_wdata_o,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,16'b0,8'b0,mpls_data,7'b0,pbb_uca,pbb_i_sid,192'b0};
        end
    end
    else
    begin
        match_field <= {807'b0,pbb_uca,pbb_i_sid,192'b0};
    end
end
    

window_filter window_filter_00(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_00_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_00_wdata_o)
    );    
window_filter window_filter_01(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_01_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_01_wdata_o)
    );    
window_filter window_filter_02(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_02_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_02_wdata_o)
    );   
window_filter window_filter_03(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_03_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_03_wdata_o)
    );    
window_filter window_filter_04(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_04_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_04_wdata_o)
    );    
window_filter window_filter_05(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_05_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_05_wdata_o)
    );    
window_filter window_filter_06(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_06_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_06_wdata_o)
    );    
window_filter window_filter_07(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_07_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_07_wdata_o)
    ); 
window_filter window_filter_08(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_08_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_08_wdata_o)
    ); 
window_filter window_filter_09(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_09_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_09_wdata_o)
    ); 
window_filter window_filter_10(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_10_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_10_wdata_o)
    ); 
  window_filter3 #(
    .OUT_LEN(3)
    )window_filter_11(
    .rst_n             (rst_n),
    //.is_vlan_i           (is_vlan),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    // .active_layer_i      (active_layer),
    .active_layer_i        (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_11_i),
    .is_ipv6             (is_ipv6),
    // .window_reg_wen_o    (window_reg_10_wen_o),
    .window_reg_wdata_o  (window_reg_11_wdata_o)
    );
window_filter window_filter_12(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_12_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_12_wdata_o)
    ); 
window_filter window_filter_13(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_13_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_13_wdata_o)
    ); 
window_filter window_filter_14(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_14_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_14_wdata_o)
    ); 
window_filter window_filter_15(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_15_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_15_wdata_o)
    ); 
window_filter window_filter_16(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_16_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_16_wdata_o)
    ); 
window_filter window_filter_17(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_17_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_17_wdata_o)
    ); 
window_filter window_filter_18(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_18_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_18_wdata_o)
    ); 
window_filter window_filter_19(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_19_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_19_wdata_o)
    ); 
window_filter window_filter_20(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_20_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_20_wdata_o)
    ); 
window_filter window_filter_21(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_21_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_21_wdata_o)
    ); 
window_filter window_filter_22(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_22_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_22_wdata_o)
    ); 
window_filter window_filter_23(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_23_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_23_wdata_o)
    ); 
window_filter window_filter_24(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_24_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_24_wdata_o)
    ); 
window_filter window_filter_25(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_25_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_25_wdata_o)
    ); 
window_filter window_filter_26(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_26_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_26_wdata_o)
    ); 
window_filter window_filter_27(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_27_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_27_wdata_o)
    ); 
window_filter8 #(
    .OUT_LEN(8)
    ) window_filter_28(
    .rst_n             (rst_n),
    //.is_vlan_i           (is_vlan),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    // .active_layer_i      (active_layer),
    .active_layer_i        (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_28_i),
    .ipv6_protocol_i     (ipv6_protocol),
    .ipv6_protocol_en_i  (ipv6_protocol_en),
    .is_ipv6             (is_ipv6),
    // .window_reg_wen_o    (window_reg_15_wen_o),
    .window_reg_wdata_o  (window_reg_28_wdata_o)
    );
window_filter8 #(
    .OUT_LEN(8)
    ) window_filter_29(
    .rst_n             (rst_n),
    //.is_vlan_i           (is_vlan),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    // .active_layer_i      (active_layer),
    .active_layer_i        (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_29_i),
    .ipv6_protocol_i     (ipv6_protocol),
    .ipv6_protocol_en_i  (ipv6_protocol_en),
    .is_ipv6             (is_ipv6),
    // .window_reg_wen_o    (window_reg_15_wen_o),
    .window_reg_wdata_o  (window_reg_29_wdata_o)
    );
window_filter window_filter_30(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_30_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_30_wdata_o)
    ); 
window_filter window_filter_31(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_31_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_31_wdata_o)
    ); 
window_filter8 #(
    .OUT_LEN(8)
    ) window_filter_32(
    .rst_n             (rst_n),
    //.is_vlan_i           (is_vlan),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    // .active_layer_i      (active_layer),
    .active_layer_i        (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_32_i),
    .ipv6_protocol_i     (ipv6_protocol),
    .ipv6_protocol_en_i  (ipv6_protocol_en),
    .is_ipv6             (is_ipv6),
    // .window_reg_wen_o    (window_reg_15_wen_o),
    .window_reg_wdata_o  (window_reg_32_wdata_o)
    );
window_filter window_filter_33(
    .rst_n               (rst_n),
    .pkt_clk_i           (pkt_clk_i),
    .pkt_data_i          (pkt_data_in_layer),
    .active_layer_i      (current_layer),
    .l2_word_cnt_i       (l2_word_cnt),
    .l3_dword_cnt_i      (l3_dword_cnt),
    .l4_dword_cnt_i      (l4_dword_cnt),
    .field_tab_item_i    (field_tab_item_33_i),
    .ether_type_i        (ether_type),
    .ether_type_en_i     (ether_type_en),
    .window_reg_wdata_o  (window_reg_33_wdata_o)
    ); 
endmodule